<?php

function retrieve_quotation_data(&$data, $kode){
    $CI = &get_instance();
    $kode = $CI->security->xss_clean($kode);
    $result = $CI->model_transaksi->getQuotationData("WHERE q.id_quotation = '". mysql_escape_string($kode)."'");
    $row = $result->row();
    
    $data["id_quotation"] = $row->id_quotation;
    $data["id_vessel"] = $row->id_vessel;
    $data["id_port"] = $row->id_port;    
    $data["tanggal_quotation"] = $row->tanggal_quotation;
    $data["nomor_quotation"] = $row->nomor_quotation;
    $data["nama_customer"] = $row->nama_customer;
    $data["id_customer"] = $row->id_customer;
    $data["alamat_detail_customer"] = $row->alamat_detail_customer;
    $data["alamat_komplit"] = $row->alamat_customer."\n".$row->kota_customer."\n".$row->kode_pos_customer;
    $data["kontak_komplit"] = $row->telepon_customer."/".$row->fax_customer."/".$row->email_customer;
    $data["attendance"] = $row->attendance;
    $data["rf_number"] = $row->rf_number;
    $data["nama_vessel"] = $row->nama_vessel;    
    $data["nama_port"] = $row->nama_port;
    $data["subject"] = $row->subject;
    $data["diskon"] = $row->diskon ? $row->diskon : 0;
    
    $data["item"] = $CI->model_transaksi->getQuotationItem($kode);
            
    $data["crc"] = $row->using_dollar_currency ? "$" : "Rp.";
    $data["using_ppn"] = $row->using_ppn;
    $data["tc"] = $row->isi_tc;
    $data["ppn"] = $row->ppn;
    $data["quote_by"] = $row->quote_by;
    $data["approved_by"] = $row->approved_by;
    $data["using_dollar_currency"] = $row->using_dollar_currency;
    
    $data["use_header"] = $CI->model_transaksi->get_scalar("SELECT tampilkan_header FROM master_setting_laporan WHERE nama_laporan = 'QUOTATION_KE_PELANGGAN'", "tampilkan_header");
}

function retrieve_delivery_data(&$data, $kode){
    $CI = &get_instance();
    $kode = $CI->security->xss_clean($kode);
    $result = $CI->model_transaksi->getDeliveryData("WHERE d.id_dn = '". mysql_escape_string($kode)."'");
    $row = $result->row();
    
    $data["id_dn"] = $row->id_dn;
    $data["id_quotation"] = $row->quotation_id;
    $data["nomor_quotation"] = $CI->model_transaksi->get_scalar("SELECT nomor_quotation FROM data_quotation_to_cust WHERE id_quotation = '$row->quotation_id'", "nomor_quotation");
    $data["item"] = $CI->model_transaksi->getDeliveryItem($row->id_dn);
    $data["tanggal_dn"] = $row->tanggal_dn;
    $data["nomor_dn"] = $row->nomor_dn;
    $data["to"] = $row->to;
    $data["rf_number"] = $row->rf_number;
    $data["delivery_to"] = $row->delivery_to;
    $data["location"] = $row->location;
    $data["subject"] = $row->subject;
    $data["checked_by"] = $row->checked_by;
    $data["delivered_by"] = $row->delivered_by;
    $data["received_by"] = $row->received_by;
    $data["received_by_2"] = $row->received_by_2;
    $data["using_dollar_currency"] = $row->using_dollar_currency;
        
    $data["use_header"] = $CI->model_transaksi->get_scalar("SELECT tampilkan_header FROM master_setting_laporan WHERE nama_laporan = 'DN_KE_PELANGGAN'", "tampilkan_header");
}

function retrieve_invoice_data(&$data, $kode, $id_po = "") {
    $CI = &get_instance();
    $kode = $CI->security->xss_clean($kode);    
    $result = $CI->model_transaksi->getInvoiceData("WHERE i.id_invoice = '". mysql_escape_string($kode)."'");    
    $row = $result->row();
    
    $data["id_invoice"] = $row->id_invoice;
    $data["tanggal_invoice"] = $row->tanggal_invoice;
    $data["nomor_invoice"] = $row->nomor_invoice;
    $data["id_po"] = $row->id_po;
    $data["crc"] = $row->using_dollar_currency;
    $data["tambahkan_ppn"] = $row->tambahkan_ppn;
    $data["penerbit_invoice"] = $row->penerbit_invoice;
    $data["diskon_iv"] = $row->diskon ? $row->diskon : 0;
    $data["item_iv"] = $CI->model_transaksi->getInvoiceItem($data["id_invoice"]);
    $data["bank"] = $CI->model_transaksi->getInvoiceBank($data["crc"]);    
    $data["list_dn"] = $CI->model_transaksi->getDeliveryData("WHERE d.id_invoice = $kode");
    
    if ($id_po == ""){
        $id_po = $row->id_po;
    }
    retrieve_purchase_data($data, $id_po);
    $data["using_dollar_currency"] = $row->using_dollar_currency;  
    $data["item"] = $data["item_iv"];
    $data["use_header"] = $CI->model_transaksi->get_scalar("SELECT tampilkan_header FROM master_setting_laporan WHERE nama_laporan = 'INVOICE_KE_PELANGGAN'", "tampilkan_header");      
}

function retrieve_purchase_data(&$data, $kode){
    $CI = &get_instance();
    $kode = $CI->security->xss_clean($kode);
    $result = $CI->model_transaksi->getPurchaseData("WHERE p.id_po = '". mysql_escape_string($kode)."'");
    $row = $result->row();
    
    $data["id_po"] = $row->id_po;
    $data["nomor_po"] = $row->nomor_po;
    $data["tanggal_po"] = $row->tanggal_po;
    $data["diskon"] = $row->diskon ? $row->diskon : 0;
    
    $data["list_quotation"] = $CI->model_transaksi->getQuotationData("WHERE q.id_quotation IN (".($row->list_quotation_id ? $row->list_quotation_id : 0).")");
    $data["item"] = $CI->model_transaksi->getPOItem($data["id_po"]);
    
    $data["using_dollar_currency"] = $row->using_dollar_currency;
    $data["nama_customer"] = $row->nama_customer;
    $data["alamat_detail_customer"] = $row->alamat_detail_customer;
    $data["alamat_komplit"] = $row->alamat_customer."\n".$row->kota_customer."\n".$row->kode_pos_customer;
    $data["kontak_komplit"] = $row->telepon_customer."/".$row->fax_customer;
    $data["email"] = $row->email_customer;
    $data["attendance"] = $row->attendance;
    $data["catatan_po"] = $row->catatan_po;
    $data["file_attachment_po"] = $row->file_attachment_po;
    
    $data["use_header"] = $CI->model_transaksi->get_scalar("SELECT tampilkan_header FROM master_setting_laporan WHERE nama_laporan = 'PO_DARI_PELANGGAN'", "tampilkan_header");
}

?>
